﻿using System;
using System.Data;
using System.Collections.Generic;
using ZX.Web.UI.Controls;
using ZX.SYS.Library;
using ZX.CRM.Bussiness;
using ZX.CRM.Library;
using ZX.DBModule;
using ZX.Common;
using ZX.BLL.Extend;
using ZX.BLL;
using ZX.Web.UI.Controls.ControlBind;
using Newtonsoft.Json;
namespace ZX.WebApp.Crm.Hodometer
{
    public partial class ProductPack : EditUIPage
    {
        BTCrmCrustomerOrder order = new BTCrmCrustomerOrder();
        BDatPhraseDetail bllDetail = new BDatPhraseDetail();
        BCrmProductPack bllPack = new BCrmProductPack();
        string strListProduct = "", strUnitId = "", strPackDetail = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            string strId = this.GetStringFromQueryString("id","");

            #region-----------jsonData-----------
            IList<V_CrmProduct> ListProduct = order.GetAllCrmCustomerProduct("");
            if (ListProduct != null && ListProduct.Count > 0)
            {
                IList<BaseEntity> _ListProduct = new List<BaseEntity>();
                foreach (var _e in ListProduct)
                {
                    _ListProduct.Add(_e);
                }
                strListProduct = _ListProduct.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");
            }
            IList<DatPhraseDetail> ListUnitId = bllDetail.GetDatPhraseDetailByClassValue("UnitId");
            if (ListUnitId != null && ListUnitId.Count > 0)
            {
                IList<BaseEntity> _ListUnitId = new List<BaseEntity>();
                foreach (var _e in ListUnitId)
                {
                    _ListUnitId.Add(_e);
                }
                strUnitId = _ListUnitId.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");
            }
            #endregion

            if (DataAction == "insert") //新增
            {
                this.ID.Value = Guid.NewGuid().ToString();
            }
            else 
            {
                V_CrmProductPack pack = bllPack.GetProductPackById(new Guid(strId));
                if (pack != null)
                {
                    this.ID.Value = pack.ID.ToString();
                    this.Packname.Value = pack.Packname;
                    this.Remark.Value = pack.Remark;
                    this.TotalMoney.Value = pack.AllMoney.ToString();
                    this.TotalRebate.Value = pack.AllRebate.ToString();

                    IList<V_CrmPackDetail> PackDetailList = bllPack.GetAllPackDetailByPackId(new Guid(strId));
                    if (PackDetailList != null && PackDetailList.Count > 0)
                    {
                        IList<BaseEntity> _ListPackDetail = new List<BaseEntity>();
                        foreach (var _e in PackDetailList)
                        {
                            _ListPackDetail.Add(_e);
                        }
                        strPackDetail = _ListPackDetail.ToJSON().Replace("\n", "").Replace("\r", "").Replace("@@", "");
                    }
                }
            }
        }

        public string strFlag
        { get { return this.GetStringFromQueryString("flag", ""); } }
        /// <summary>
        /// 标题
        /// </summary>
        public string PageTitle
        { get { return this.GetStringFromQueryString("title", ""); } }
        /// <summary>
        /// 产品列表
        /// </summary>
        public string ListCrmProduct
        { get { return strListProduct; } }
        /// <summary>
        /// 计量单位
        /// </summary>
        public string ListUnitId
        { get { return strUnitId; } }
        /// <summary>
        /// 产品信息
        /// </summary>
        public string ListPackDetail
        { get { return strPackDetail; } }
    }
}